import java.io.*;
import java.util.Scanner;

public class Demo462 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner scanner =new Scanner(System.in);
        System.out.println("请输入要复制的文件的目录");
        String rootDirPath = scanner.next();
        File rootDir = new File(rootDirPath);
        if(!rootDir.exists()){
            return;
        }
        if(!rootDir.isFile()){
            return;
        }
        System.out.println("请输入要复制到的路径");
        String destDirPath = scanner.next();
        File destDir = new File(destDirPath);
        if(!destDir.exists()){
            return;
        }
        if(destDir.isDirectory()){
            return;
        }
        try(InputStream inputStream = new FileInputStream(rootDir);
            OutputStream outputStream = new FileOutputStream(destDir)){
byte[] buffer = new byte[1024];
int b = 0;
while(true){
    b = inputStream.read(buffer );
    if(b==-1){
        break;
    }
    outputStream.write(buffer);
}
outputStream.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
